<?php

namespace app\admin\controller;
use app\common\model\Notice;
use think\Controller;
/**
 * 公告管理
 */
class Announce extends Base
{
    protected $model;
    public function __construct()
    {
        parent::__construct();
        $this->model = new Notice();
    }
    /**
     * [index description]
     * @Author   lcx
     * @DateTime 2017-09-11
     * @desc     公告列表
     * @param               {string}
     * @return   {json}
     * @return   [type]     [description]
     */
    public function index(){
        $map['status'] = 1;
        $map['isshow'] = 1;
        $Nowpage = input('get.page') ? input('get.page'):1;
        $limits = config('pagesize');
        //获取数据
        $lists = $this->model->getAll($map,'*',$Nowpage,$limits);
        $count = $this->model->where($map)->count();//计算总页面
        $allpage = intval(ceil($count / $limits));

        //模板输出
        $this->assign('Nowpage', $Nowpage); //当前页
        $this->assign('allpage', $allpage); //总页数
        $this->assign('count',$count);
        if(input('get.page')){
            return json($lists);
        }
        return $this->view->fetch();
    }
    public function detail(){
        $id = input('param.id');
        if(empty($id)){
            return json(['code' => -1, 'data' => '', 'msg' =>'缺少参数ID']);
        }
        $data = $this->model->search($id);
        return json(['code' => 1, 'data' => $data, 'msg' =>'获取数据成功']);
    }
}